@extends('backstage.layout.master')
@section('title', '添加标签')
@section('style')
        <!-- page specific plugin styles -->
<link rel="stylesheet" href="/assets/css/jquery-ui-1.10.3.custom.min.css"/>
<link rel="stylesheet" href="/assets/css/chosen.css"/>
<link rel="stylesheet" href="/assets/css/datepicker.css"/>
<link rel="stylesheet" href="/assets/css/bootstrap-timepicker.css"/>
<link rel="stylesheet" href="/assets/css/daterangepicker.css"/>
<link rel="stylesheet" href="/assets/css/colorpicker.css"/>
<!-- fonts -->

@stop
@section('content')
    <div class="breadcrumbs" id="breadcrumbs">
        <script type="text/javascript">
            try {
                ace.settings.check('breadcrumbs', 'fixed')
            } catch (e) {
            }
        </script>

        <ul class="breadcrumb">
            <li>
                <i class="icon-home home-icon"></i>
                <a target="_blank" href="backstage/home">主页</a>
            </li>

            <li class="active">
                <a target="_blank" href="/backstage/source-pic/source-pic-tag-list">素材列表</a>
            </li>
            <li>
                添加标签
            </li>
        </ul><!-- .breadcrumb -->
    </div>
    <div class="page-content">
        <div class="row">
            <div class="col-xs-12">
                <!-- PAGE CONTENT BEGINS -->
                <div class="page-header">
                    <h1>
                        标签
                        <small>
                            <i class="icon-double-angle-right"></i>
                            标签
                        </small>
                    </h1>
                </div>
                <div class="row">
                    <div class="col-xs-12">
                        <!-- PAGE CONTENT BEGINS -->
                        <div class="alert alert-info">
                            <i class="icon-hand-right"></i>
                            <!-- 信息-->
                        </div>
                        <div class="space-4"></div>
                        <form class="form-horizontal" role="form" action= "/backstage/source-pic/update-source-pic-tag" method="post" enctype="multipart/form-data">
                            <div class="form-group {{$errors->first('tag_name')!=""?'has-error':''}}">
                                <label class="col-sm-3 control-label no-padding-right" for="form-field-1"> 标签名</label>

                                <div class="col-sm-4">
                                    <input type="text" name="tag_name" value="{{isset($tag->name)?$tag->name:''}}" placeholder="标签名" class="width-100" id="tag_name">
                                    <input type="hidden" name="tag_id" value={{isset($tag->id)?$tag->id:0}}>
                                    <input type="hidden" name="_token" value="<?php echo csrf_token(); ?>">
                                    <input type="hidden" name="app_id" value=1>
                                </div>
                                <div class="col-sm-5">
                                    <div class="help-block col-xs-12 col-sm-reset inline" id="tag_name_warn"> {{$errors->first('tag_name')}}</div>
                                </div>
                            </div>
                            <div class="space-4"></div>
                            <div class="col-md-offset-2 "  style="margin-left: 32%">
                                <img class="carousel-image img-responsive" src="{{isset($tag->original_image)?$tag->original_image:''}}" width="100px"/>
                            </div>
                            <div class="space-4"></div>
                            <div class="form-group {{$errors->first('original_image')!=""?'has-error':''}}">
                                <label class="col-sm-3 control-label no-padding-right" for="form-field-1">
                                    Ico图片 </label>
                                <div class="col-sm-4">
                                    <input type="file" name="original_image" placeholder="Ico图片">
                                </div>
                                <div class="col-sm-5">
                                    <input type="hidden" name="_token" value="<?php echo csrf_token(); ?>">
                                    <div class="help-block col-xs-12 col-sm-reset inline"> {{$errors->first('original_image')}}</div>
                                </div>
                            </div>
                            <div class="form-group {{$errors->first('sort_type')!=""?'has-error':''}}">
                                <label class="col-sm-3 control-label no-padding-right" for="form-field-1"> 排序</label>
                                <div class="col-sm-4">
                                    <select id="sort_type" name="sort_type">
                                        <option @if($tag->sort_type==1) selected @endif value=1>已使用数量</option>
                                        <option @if($tag->sort_type==2) selected @endif value=2>更新时间(倒序)</option>
                                    </select>
                                </div>
                                <div class="col-sm-5">
                                    <div class="help-block col-xs-12 col-sm-reset inline"> {{$errors->first('sort_type')}}</div>
                                </div>
                            </div>
                            <div class="space-4"></div>
                            <div class="form-group {{$errors->first('tag_type')!=""?'has-error':''}}">
                                <label class="col-sm-3 control-label no-padding-right" for="form-field-1"> 获取模板范围</label>
                                <div class="col-sm-4">
                                    <select id="tag_type" name="tag_type">
                                        <option @if($tag->tag_type==1) selected @endif value=1>全部</option>
                                        <option @if($tag->tag_type==2) selected @endif value=2>部分(具体添加)</option>
                                    </select>
                                </div>
                                <div class="col-sm-5">
                                    <div class="help-block col-xs-12 col-sm-reset inline"> {{$errors->first('tag_type')}}</div>
                                </div>
                            </div>
                            <div class="space-4 some_temp" @if($tag->tag_type==1) style="display: none" @endif></div>
                            <div class="form-group some_temp {{$errors->first('p_tag_ids')!=""?'has-error':''}}" @if($tag->tag_type==1) style="display: none" @endif>
                                <label class="col-sm-3 control-label no-padding-right" for="form-field-1"> 绑在标签下</label>

                                <div class="col-sm-4">
                                    <input  type="text" placeholder="搜索关键字"  id="tag_search_keyword" style="width: 80px">
                                    <select id="tag_search_res"  onchange="resultChange(this.options,this.options.selectedIndex)">
                                        @foreach($un_bound_tags as $un_bound_tag)
                                            <option value={{isset($un_bound_tag->id)?$un_bound_tag->id:0}}>{{isset($un_bound_tag->name)?$un_bound_tag->name:''}}({{isset($un_bound_tag->id)?$un_bound_tag->id:''}})</option><br />
                                        @endforeach
                                    </select>
                                    <input type="button" value="+" class="button" onclick="addSourcePicTag()" />
                                    <br/>
                                    <div id="selected-tag-div">
                                        @if(isset($tag->p_tags))
                                            @foreach($tag->p_tags as $p_tag)
                                                <input name="p_tag_ids[]" type="checkbox" checked value={{isset($p_tag->tag_id)?$p_tag->tag_id:0}}>{{isset($p_tag->tag_name)?$p_tag->tag_name:''}}(id:{{isset($p_tag->tag_id)?$p_tag->tag_id:0}}) <br/>
                                            @endforeach
                                        @endif
                                    </div>
                                </div>
                                <div class="col-sm-5">
                                    <div class="help-block col-xs-12 col-sm-reset inline" id="p_tag_ids"> {{$errors->first('p_tag_ids')}}</div>
                                </div>
                            </div>
                            <div class="space-4"></div>
                            <div class="form-group {{$errors->first('description')!=""?'has-error':''}}">
                                <label class="col-sm-3 control-label no-padding-right" for="form-field-1"> 标签描述</label>

                                <div class="col-sm-4">
                                    <textarea class="form-control" name="description" id="form-field-8"
                                              placeholder="标签描述">{{isset($tag->description)?$tag->description:''}}</textarea>
                                </div>
                                <div class="col-sm-5">
                                    <div class="help-block col-xs-12 col-sm-reset inline"> {{$errors->first('description')}}</div>
                                </div>
                            </div>
                            <div class="clearfix form-actions">
                                <div class="col-md-offset-3 col-md-9">
                                    <button class="btn btn-info" type="submit">
                                        <i class="icon-ok bigger-110"></i>
                                            更新
                                    </button>
                            </div>
                            </div>
                        </form>
                    </div><!-- /.col -->
                </div>
                <!-- PAGE CONTENT ENDS -->
            </div><!-- /.col -->
        </div><!-- /.row -->
    </div><!-- /.page-content -->
@stop
@section('script')
    <script src="/backstage/js/sourcePic/sourcePic.js"></script>
    <script type="text/javascript">
        _token = '{{csrf_token()}}';
        $(function(){
            $("#original_image ").ace_file_input({
                no_file: '还未选择图片',
                btn_choose: '选择',
                btn_change: '重新选择',
                droppable: false,
                onchange: null,
                thumbnail: true //| true | large
                //whitelist:'gif|png|jpg|jpeg'
                //blacklist:'exe|php'
                //onchange:''
                //
            });
            /****
             * 获取模板范围
             */
            $('#tag_type').change(function() {
                var tag_type=parseInt($(this).val());
                console.log('tag_type:'+tag_type);
                if(tag_type==1){
                    $('.some_temp').hide();
                }else if(tag_type==2){
                    $('.some_temp').show();
                }
            });
        });
        function trim(s){
            return s.replace(/(^\s*)|(\s*$)/g, "");
        }
    </script>
@stop
